/*
 * Copyright 2012 jsm.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.abiwebz.office.rm;


import java.util.prefs.Preferences;
import net.abiwebz.office.rm.database.DatabaseDrivers;
import net.abiwebz.office.rm.database.configuration.DbConfigWizardAction;
import net.abiwebz.office.rm.database.security.SecurityManager;
import org.openide.modules.ModuleInstall;
import org.openide.util.NbPreferences;

/**
 * This class is used by the NetBeans platform to restore (or start) the plugin.
 * 
 * @author Jonathan St-Michel <jonathan@abiwebz.net>
 */
public class Installer extends ModuleInstall {

    /**
     * Display the login screen for OffiCE RM when the module is loading. The
     * Login Screen is generated by the SecurityManager.
     */
    @Override
    public void restored() {
        // Load configured driver or start the configuration
        Preferences p = NbPreferences.forModule(DatabaseDrivers.class);
        if(!p.getBoolean("database.driver.set", false)){
            // We need to configure the database
            new DbConfigWizardAction().execute(); // Execute the configuration wizard
        }
        // Use the SecurityManager class to generate a login screen for the
        // default connection. If credentials are valid then the connection is
        // created.
        SecurityManager.get().login();
    }
    
}